from django.shortcuts import render
import pymysql
from django.http import JsonResponse, FileResponse
from django.shortcuts import HttpResponse, render
import json
import numpy
import copy
import random
from .Judge import Judge
from .Skill import Skill


class Damage:
    def __init__(self, res):
        self.total_time = 350
        self.breaktime = 999
        self.breakcishu = 0
        self.duan = False
        self.cal_num = 0
        self.res = res
        self.jinengxulie = res["jinengxulie"]
        self.jinengxulie_xunhuan = res["jinengxulie_xunhuan"]

        self.skill_sim_log = []
        self.skill_log = []
        self.current_buff = []
        self.feijian_level = 0
        self.yaoxing = res["yaoxing"]
        self.niluan = 0
        self.niluan_buff = []
        self.niluan_skill = ''
        self.cangji_delay = [-1]
        self.cangji_buff = []
        self.cangji_yaoxing = 0
        self.cangji_max = 0
        self.niluan_tiaoshu = 7
        self.qianzhi = False
        # 沾衣大附魔
        self.shangku_2 = False
        self.shangku_2_gou = 0
        if res["qixue_9"] == "2":  # 疾根
            self.niluan_tiaoshu = 8
        self.current = {
            "name": [""],
            "time": 0,
        }
        self.target = {
            "商陆缀寒": {
                "存在": False,
                "跳数": 0,
                "GCD": Skill(self.res).shang[6],
                "cold_down": Skill(self.res).shang[6],
            },
            "逆乱": {
                "存在": False,
                "跳数": 0,
                "GCD": Skill(self.res).ni[6],
                "cold_down": Skill(self.res).ni[6],
            },
            "沾衣未妨": {
                "存在": False,
                "跳数": 0,
                "GCD": 0.75,
                "cold_down": 0.75,
            },
            "沾衣未妨_附魔": {
                "存在": False,
                "跳数": 0,
                "GCD": 0.75,
                "cold_down": 0.75,
            },
            "川乌射罔": {
                "存在": False,
                "跳数": 0,
                "GCD": Skill(self.res).xi[6],
                "cold_down": Skill(self.res).xi[6],
            },
            "苍棘缚地": {
                "存在": False,
                "跳数": 0,
                "GCD": 2,
                "cold_down": 3,
            },
            "且待时休": {
                "存在": False,
                "跳数": 0,
                "GCD": 1,
                "cold_down": 1,
            },
            "且待时休_苍": {
                "存在": False,
                "跳数": 0,
                "GCD": 1,
                "cold_down": 1,
            },

        }
        self.skills = {
            "商陆缀寒": {
                "CD": 0,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "钩吻断肠": {
                "CD": 0,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "川乌射罔": {
                "CD": 10,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "沾衣未妨": {
                "CD": 20,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "且待时休": {
                "CD": 47,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "银光照雪": {
                "CD": 10,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "惊鸿掠水": {
                "CD": 30,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "回风微澜": {
                "CD": 0,
                "充能": 0,
                "剩余充能": 0,
                "消耗": 0,
                "cold_down": 0,
            },
            "含锋破月": {
                "CD": 20,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "飞叶满襟": {
                "CD": 0,
                "充能": 0,
                "剩余充能": 0,
                "消耗": 0,
                "cold_down": 0,
            },
            "凌然天风": {
                "CD": 20,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "千枝绽蕊": {
                "CD": 3,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "苍棘缚地": {
                "CD": 25,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "紫叶沉疴": {
                "CD": 36,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "飞剑": {
                "CD": 6,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "飞剑·意": {
                "CD": 0,
                "充能": 0,
                "剩余充能": 0,
                "消耗": 0,
                "cold_down": 0,
            },
            "手附魔": {
                "CD": 16.75,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "橙武": {
                "CD": 26,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "乱暮浊茵阵": {
                "CD": 10,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "腰坠": {
                "CD": 180,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
            "飘黄": {
                "CD": 70,
                "充能": 1,
                "剩余充能": 1,
                "消耗": 0,
                "cold_down": 0,
            },
        }
        # 手大附魔
        self.skills["手附魔"]["CD"] = 10

        # 奇穴2-1[鸩羽]
        if self.res["qixue_2"] == "1":  # [鸩羽]
            self.skills["川乌射罔"]["充能"] = 2
            self.skills["川乌射罔"]["剩余充能"] = 2
        # 奇穴5-2 [沉疴]
        if self.res["qixue_5"] == "2":
            self.skills["紫叶沉疴"]["CD"] = 26
        self.buffs = {
            "触融": {
                "存在": False,
                "time": 0,
            },
            "相使": {
                "存在": False,
                "time": 0,
            },
            "凄骨": {
                "存在": False,
                "time": 0,
            },
            "紫叶": {
                "存在": False,
                "time": 0,
            },
            "千枝绽蕊": {
                "存在": False,
                "time": 0,
            },
            "沾衣": {
                "存在": False,
                "time": 0,
            },
            "飞剑·意": {
                "存在": False,
                "time": 0,
            },
            "春节阵·朱雀": {
                "存在": False,
                "time": 0,
            },
            "沾附魔CD": {
                "存在": False,
                "time": 0,
            },
            "橙武": {
                "存在": False,
                "time": 0,
            },
            "风": {
                "存在": False,
                "time": 0,
            },
            "飘黄": {
                "存在": False,
                "time": 0,
            },
            "落黄": {
                "存在": False,
                "time": 0,
            },
            "飘黄内置CD": {
                "存在": False,
                "time": 0,
            },

        }

        if "春节阵·朱雀" in self.res["buff"]:
            self.buffs["春节阵·朱雀"]["存在"] = True
            self.buffs["春节阵·朱雀"]["time"] = 20

    # 技能释放日志
    def log(self, skill_name, damage, buff, time_stamp):
        self.skill_log.append(
            {
                "name": skill_name,
                "damage": int(damage[0]),
                "buff": buff,
                "time_stamp": time_stamp,
            }
        )

    def sim_log(self, skill_name, skill_type, time_stamp):
        self.skill_sim_log.append(
            {
                "name": skill_name,
                "type": skill_type,
                "time_stamp": time_stamp,
            }
        )

    # 每帧开始的时候刷新BUFF
    def time_start(self, t):
        # 将所有触发的buff添加进即时buff列表
        for key in self.buffs.keys():
            if self.buffs[key]["存在"]:
                self.current_buff.append(key)
        if self.cangji_delay[0] == 0:
            self.skills["苍棘缚地"]["剩余充能"] -= 1
            self.skills["苍棘缚地"]["cold_down"] = self.skills["苍棘缚地"]["CD"]
            self.target["苍棘缚地"]["存在"] = True
            self.target["苍棘缚地"]["跳数"] = 5
            self.target["苍棘缚地"]["cold_down"] = 3.25
            self.cangji_buff = self.current_buff.copy()
            self.cangji_max = 0
            self.cangji_delay[0] -= 0.0625

        else:
            self.cangji_delay[0] -= 0.0625

    # 结算dot
    def dot_pass(self, t):
        buff_list = copy.copy(self.current_buff)
        # buff_list = []
        # buff = copy.copy(self.current_buff)
        # # BUFF
        # if "凄骨" in buff :
        #     buff_list.append("凄骨")
        # if "相使" in buff:
        #     buff_list.append("相使")
        # if "千枝绽蕊" in buff:
        #     buff_list.append("千枝绽蕊")
        for key, value in self.target.items():
            if self.target[key]["存在"] and self.target[key]["跳数"] > 0:
                self.target[key]["cold_down"] -= 0.0625
                if self.target[key]["cold_down"] == 0:
                    if key == "商陆缀寒":
                        damage = Judge(self.res, Skill(self.res).shang, buff_list).d()
                        dam = damage
                        self.log("商陆缀寒", dam, buff_list, t)
                        self.niluan_skill = '商陆缀寒'
                        # 商陆缀寒温度-1
                        self.yaoxing -= 1
                        if self.yaoxing < -5:
                            self.yaoxing = -5
                        elif self.yaoxing > 5:
                            self.yaoxing = 5
                        if self.yaoxing > -1:  # 温性触发中和
                            self.wu(t, '商陆缀寒')
                        self.shou(t)
                        self.piao(t)
                        if self.target[key]["跳数"] == 0:
                            self.target[key]["存在"] = False
                        # 触发飞剑
                        # self.feijian_yi(t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        # if self.target[key]["跳数"] == 0 :
                        #     self.target[key]["存在"] = False
                        #     self.sim_log("祝由·火离","火离消失",t)
                        #     self.zengbu_reduce = 2
                    elif key == "逆乱":
                        # if self.niluan_skill == "川乌射罔":
                        #     skill_buff_wu = copy.copy(Skill(self.res).ni)
                        #     skill_buff_wu[4] = Skill(self.res).xi[4]
                        #     skill_buff_wu[5] = Skill(self.res).xi[5]
                        # elif self.niluan_skill == "商陆缀寒":
                        #     skill_buff_wu = copy.copy(Skill(self.res).ni)
                        #     skill_buff_wu[4] = Skill(self.res).shang[4]
                        #     skill_buff_wu[5] = Skill(self.res).shang[5]
                        # elif self.niluan_skill == "钩吻断肠":
                        #     skill_buff_wu = copy.copy(Skill(self.res).ni)
                        #     skill_buff_wu[4] = Skill(self.res).gou[4]
                        #     skill_buff_wu[5] = Skill(self.res).gou[5]
                        # else:
                        #     skill_buff_wu = copy.copy(Skill(self.res).ni)
                        skill_buff_wu = copy.copy(Skill(self.res).ni)

                        if "凄骨" not in buff_list and "凄骨" in self.niluan_buff:
                            self.niluan_buff.remove("凄骨")
                        damage = Judge(self.res, skill_buff_wu, self.niluan_buff).d()
                        dam = (int(damage[0] * self.niluan), damage[1], damage[2])
                        self.log("逆乱", dam, buff_list, t)
                        # print(t,"火离",self.target["火离"],self.zengbu)
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        self.piao(t)
                        # 触发飞剑
                        # self.feijian_yi(t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        if self.target[key]["跳数"] == 0:
                            self.target[key]["存在"] = False
                            self.sim_log("逆乱", "逆乱消失", t)
                            self.niluan = 0
                            self.niluan_buff = []
                    elif key == "川乌射罔":

                        damage = Judge(self.res, Skill(self.res).xi, buff_list).d()
                        self.niluan_skill = '川乌射罔'
                        self.log("川乌射罔", damage, buff_list, t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        # 川乌射罔温度+1
                        self.yaoxing += 1
                        if self.yaoxing < -5:
                            self.yaoxing = -5
                        elif self.yaoxing > 5:
                            self.yaoxing = 5
                        if self.yaoxing < 1:  # 温性触发中和
                            self.wu(t, '川乌射罔')
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        self.piao(t)
                        if self.target[key]["跳数"] == 0:
                            if self.duan == False:
                                # 奇穴8-1[凄骨]
                                if self.res["qixue_8"] == "1":
                                    self.current_buff.append("凄骨")
                                    self.buffs["凄骨"]["存在"] = True
                                    self.buffs["凄骨"]["time"] = 12
                                self.target[key]["存在"] = False
                                # 触发逆乱
                                self.niluan_buff = self.current_buff.copy()  # 逆乱快照
                                self.niluan += 1
                                self.target['逆乱']['跳数'] = self.niluan_tiaoshu
                                if self.niluan > 8:
                                    self.niluan = 8
                                elif self.niluan == 1:
                                    self.target['逆乱']['存在'] = True
                                    self.target["逆乱"]["cold_down"] = Skill(self.res).ni[6]

                                # 橙武
                                if self.buffs["橙武"]["存在"] == True:
                                    # self.cal_num += 1
                                    for i in range(0, 4):
                                        self.yaoxing -= 1
                                        if self.yaoxing < -5:
                                            self.yaoxing = -5
                                        elif self.yaoxing > 5:
                                            self.yaoxing = 5
                                        if self.yaoxing > -1:  # 触发中和
                                            self.wu(t, '橙武')
                            else:
                                self.target[key]["存在"] = False
                                self.duan = False
                    elif key == "且待时休":
                        damage = Judge(self.res, Skill(self.res).qie, buff_list).d()
                        self.log("且待时休", damage, buff_list, t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        self.piao(t)
                        if self.target[key]["跳数"] == 0:
                            self.target[key]["存在"] = False
                    elif key == "且待时休_苍":
                        damage = Judge(self.res, Skill(self.res).qie, buff_list).d()
                        self.log("且待时休", damage, buff_list, t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        self.piao(t)
                        if self.target[key]["跳数"] == 0:
                            self.target[key]["存在"] = False
                    elif key == "沾衣未妨":
                        damage = Judge(self.res, Skill(self.res).zhan, buff_list).d()
                        self.niluan_skill = '沾衣未妨'
                        self.log("沾衣未妨", damage, buff_list, t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        # print(t,self.yaoxing)
                        # 沾衣未妨温度-1
                        self.yaoxing -= 1
                        if self.yaoxing < -5:
                            self.yaoxing = -5
                        elif self.yaoxing > 5:
                            self.yaoxing = 5
                        if self.yaoxing > -1:  # 寒性触发中和
                            self.wu(t, '沾衣未妨')
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        self.piao(t)
                        if self.target[key]["跳数"] == 0:
                            self.target[key]["存在"] = False
                    elif key == "沾衣未妨_附魔":
                        damage = Judge(self.res, Skill(self.res).zhan, buff_list).d()
                        self.niluan_skill = '沾衣未妨'
                        self.log("沾衣未妨", damage, buff_list, t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        # print(t,self.yaoxing)
                        # 沾衣未妨温度-1
                        self.yaoxing -= 1
                        if self.yaoxing < -5:
                            self.yaoxing = -5
                        elif self.yaoxing > 5:
                            self.yaoxing = 5
                        if self.yaoxing > -1:  # 寒性触发中和
                            self.wu(t, '沾衣未妨')
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        self.piao(t)
                        if self.target[key]["跳数"] == 0:
                            self.target[key]["存在"] = False
                    elif key == "苍棘缚地":
                        if self.cangji_yaoxing > 0:
                            cangji_yaoxing_k = 1.05
                        else:
                            cangji_yaoxing_k = 1
                        if self.res["qixue_4"] == "1":  # 灵荆
                            cangji_yaoxing_k = 1.25
                        damage = Judge(self.res, Skill(self.res).cang, self.cangji_buff).d()
                        dam = (int(damage[0] * cangji_yaoxing_k), damage[1], damage[2])
                        self.log("苍棘缚地", dam, buff_list, t)
                        self.target[key]["跳数"] -= 1
                        self.target[key]["cold_down"] = self.target[key]["GCD"]
                        # 触发橙武
                        # self.cw(t)
                        # 触发手大附魔
                        self.shou(t)
                        self.piao(t)
                        if self.target[key]["跳数"] == 0:
                            self.target[key]["存在"] = False
                            self.target["且待时休_苍"]["存在"] = False
                            self.target["且待时休_苍"]["跳数"] = 0

    # 时间结算
    def time_pass(self, t):
        self.dot_pass(t)
        self.current_buff = []  # 清空即时buff列表
        # 转GCD
        self.current["time"] -= 0.0625
        if self.current["time"] == 0:
            self.current["name"] = [""]
        elif self.current["time"] < 0:
            self.current["time"] = 0
            self.current["name"] = [""]
        # 技能计时
        for key, value in self.skills.items():
            if self.skills[key]["充能"] > self.skills[key]["剩余充能"]:
                self.skills[key]["cold_down"] -= 0.0625
                if self.skills[key]["cold_down"] <= 0:
                    self.skills[key]["剩余充能"] += 1
                    if self.skills[key]["充能"] > self.skills[key]["剩余充能"]:
                        self.skills[key]["cold_down"] = self.skills[key]["CD"]
        # buff计时
        for key, value in self.buffs.items():
            if self.buffs[key]["存在"] is True:
                self.buffs[key]["time"] -= 0.0625
                if self.buffs[key]["time"] <= 0:
                    self.buffs[key]["存在"] = False

    # 飞剑攒层数
    # def feijian_zan(self,t):
    #     if "飞剑·意" in self.res["buff"]:
    #         if self.skills["飞剑"]["剩余充能"] == 1:
    #             self.skills["飞剑"]["剩余充能"] = 0
    #             self.skills["飞剑"]["cold_down"] = self.skills["飞剑"]["CD"]
    #             self.feijian_level += 1
    #             if self.feijian_level == 5:
    #                 self.skills["飞剑·意"]["剩余充能"] = 1
    #             elif self.feijian_level > 5:
    #                 self.feijian_level = 5
    #             buff = copy.copy(self.current_buff)
    #             damage = Judge(self.res,Skill(self.res).feijian,buff).d()
    #             self.log("剑风",damage,buff,t)
    #             self.sim_log("剑风","武器被动",t)
    # 使用飞剑武器
    # def feijian_yi(self,t):
    #     if "飞剑·意" in self.res["buff"]:
    #         self.feijian_zan(t)
    #         if self.skills["飞剑·意"]["剩余充能"] == 1:
    #             self.skills["飞剑·意"]["剩余充能"] = 0
    #             self.feijian_level = 0
    #             self.current_buff.append("飞剑·意")
    #             self.buffs["飞剑·意"]["存在"] = True
    #             self.buffs["飞剑·意"]["time"] = 6
    #             buff = copy.copy(self.current_buff)
    #             damage = [0,]
    #             self.log("飞剑·意",damage,buff,t)
    #             self.sim_log("飞剑·意","武器特效",t)
    # 无方中和
    def wu(self, t, name):
        buff = copy.copy(self.current_buff)
        # 2021.12.30第二次削弱中和技能吃奇穴秘籍，现在彻底不吃奇穴秘籍效果了
        # if name == "川乌射罔":
        #     skill_buff_wu = copy.copy(Skill(self.res).wu)
        #     skill_buff_zi = copy.copy(Skill(self.res).wu)
        #     skill_buff_ji = copy.copy(Skill(self.res).wu)
        #     skill_buff_wu[4] = Skill(self.res).xi[4]
        #     skill_buff_wu[5] = Skill(self.res).xi[5]
        #     skill_buff_zi[4] = Skill(self.res).xi[4]
        #     skill_buff_zi[5] = Skill(self.res).xi[5]
        #     skill_buff_ji[4] = Skill(self.res).xi[4]
        #     skill_buff_ji[5] = Skill(self.res).xi[5]
        #     if self.res["qixue_2"] == "1":  # [鸩羽]
        #         skill_buff_wu[4] -= 0.1
        #         skill_buff_wu[5] -= 0.1
        #         skill_buff_zi[4] -= 0.1
        #         skill_buff_zi[5] -= 0.1
        #         skill_buff_ji[4] -= 0.1
        #         skill_buff_ji[5] -= 0.1
        # elif name == "商陆缀寒":
        #     skill_buff_wu = copy.copy(Skill(self.res).wu)
        #     skill_buff_zi = copy.copy(Skill(self.res).wu)
        #     skill_buff_ji = copy.copy(Skill(self.res).wu)
        #     skill_buff_wu[4] = Skill(self.res).shang[4]
        #     skill_buff_wu[5] = Skill(self.res).shang[5]
        #     skill_buff_zi[4] = Skill(self.res).shang[4]
        #     skill_buff_zi[5] = Skill(self.res).shang[5]
        #     skill_buff_ji[4] = Skill(self.res).shang[4]
        #     skill_buff_ji[5] = Skill(self.res).shang[5]
        # elif name == "钩吻断肠":
        #     skill_buff_wu = copy.copy(Skill(self.res).wu)
        #     skill_buff_zi = copy.copy(Skill(self.res).wu)
        #     skill_buff_ji = copy.copy(Skill(self.res).wu)
        #     skill_buff_wu[4] = Skill(self.res).gou[4]
        #     skill_buff_wu[5] = Skill(self.res).gou[5]
        #     skill_buff_zi[4] = Skill(self.res).gou[4]
        #     skill_buff_zi[5] = Skill(self.res).gou[5]
        #     skill_buff_ji[4] = Skill(self.res).gou[4]
        #     skill_buff_ji[5] = Skill(self.res).gou[5]
        # else:
        #     skill_buff_wu = Skill(self.res).wu
        #     skill_buff_zi = Skill(self.res).zi
        #     skill_buff_ji = Skill(self.res).ji
        skill_buff_wu = Skill(self.res).wu
        skill_buff_zi = Skill(self.res).zi
        skill_buff_ji = Skill(self.res).ji
        damage = Judge(self.res, skill_buff_wu, buff).d()
        self.log("无方中和", damage, buff, t)
        self.target['逆乱']['存在'] = True
        # self.sim_log("无方中和", "触发", t)
        # 触发奇穴3-2[结草]
        if self.cangji_delay[0] < -3 and self.cangji_max < 4:
            self.target["苍棘缚地"]["跳数"] += 1
            self.cangji_max += 1
        # 触发奇穴10-1紫伏
        if self.res["qixue_10"] == "1" and self.buffs["紫叶"]["存在"] == True and self.buffs["紫叶"]["time"] < 15:  # 紫伏
            damage = Judge(self.res, skill_buff_zi, buff).d()
            self.log("紫伏", damage, buff, t)
            # self.sim_log("紫伏", "触发", t)
        # 触发逆乱
        self.niluan_buff = self.current_buff.copy()  # 逆乱快照
        self.niluan += 1
        self.target['逆乱']['跳数'] = self.niluan_tiaoshu
        if self.niluan > 8:
            self.niluan = 8
        elif self.niluan == 1:
            self.target['逆乱']['存在'] = True
            self.target["逆乱"]["cold_down"] = Skill(self.res).ni[6]
        # 触发阵眼
        if self.res["zhenyan"] == '7' and self.skills["乱暮浊茵阵"]["剩余充能"] >= 1:
            self.skills["乱暮浊茵阵"]["剩余充能"] -= 1
            self.skills["乱暮浊茵阵"]["cold_down"] = self.skills["乱暮浊茵阵"]["CD"]
            if name == "川乌射罔":
                damage = [Judge(self.res, Skill(self.res).xi, buff).zhen()[0], '乱暮浊茵阵', Skill(self.res).xi]
                zhen_chongshu = Judge(self.res, Skill(self.res).xi, buff).zhen()[-1]
            elif name == "商陆缀寒":
                damage = [Judge(self.res, Skill(self.res).shang, buff).zhen()[0], '乱暮浊茵阵', Skill(self.res).shang]
                zhen_chongshu = Judge(self.res, Skill(self.res).shang, buff).zhen()[-1]
            elif name == "钩吻断肠":
                damage = [Judge(self.res, Skill(self.res).gou, buff).zhen()[0], '乱暮浊茵阵', Skill(self.res).gou]
                zhen_chongshu = Judge(self.res, Skill(self.res).gou, buff).zhen()[-1]
            else:
                damage = [Judge(self.res, Skill(self.res).zhan, buff).zhen()[0], '乱暮浊茵阵', Skill(self.res).zhan]
                zhen_chongshu = Judge(self.res, Skill(self.res).zhan, buff).zhen()[-1]
            
            damage = [Judge(self.res, Skill(self.res).zhan, buff).zhen()[0], '乱暮浊茵阵', Skill(self.res).zhan]
            zhen_chongshu = Judge(self.res, Skill(self.res).zhan, buff).zhen()[-1]
            # print(name,damage)
            self.log("乱暮浊茵阵", damage, buff, t)
            self.sim_log("乱暮浊茵阵", zhen_chongshu, t)
        # 触发奇穴9-2疾根
        if self.res["qixue_9"] == "2" and self.niluan >= 4:
            damage = Judge(self.res, skill_buff_ji, buff).d()
            self.log("疾根", damage, buff, t)
            # self.sim_log("疾根", "触发", t)

    # 紫叶沉疴
    def zi(self, t):
        if self.current["time"] == 0 and self.skills["紫叶沉疴"]["剩余充能"] >= 1:
            self.current["time"] = Skill(self.res).shang[6]
            self.skills["紫叶沉疴"]["剩余充能"] -= 1
            self.skills["紫叶沉疴"]["cold_down"] = self.skills["紫叶沉疴"]["CD"]
            if "腰坠·风特效" in self.res["buff"] and self.skills["腰坠"]["剩余充能"] >= 1:
                self.skills["腰坠"]["剩余充能"] -= 1
                self.skills["腰坠"]["cold_down"] = self.skills["腰坠"]["CD"]
                self.current_buff.append("风")
                self.buffs["风"]["存在"] = True
                self.buffs["风"]["time"] = 15
                self.sim_log("开腰坠了！", "爆发", t)
                self.shou(t)
                self.piao(t)

            self.niluan_skill = '紫叶沉疴'
            if self.res["qixue_10"] == "1":  # 紫伏
                self.buffs["紫叶"]["存在"] = True
                self.buffs["紫叶"]["time"] = 15
            if self.res["qixue_5"] == "2":  # 沉疴
                buff = copy.copy(self.current_buff)
                damage = Judge(self.res, Skill(self.res).zi_li, buff).d()
                # 沉疴温度+1
                self.yaoxing += 1
                if self.yaoxing < -5:
                    self.yaoxing = -5
                elif self.yaoxing > 5:
                    self.yaoxing = 5
                if self.yaoxing < 1:  # 触发中和
                    self.wu(t, '紫叶沉疴')
            else:
                buff = copy.copy(self.current_buff)
                damage = [0, ]
            self.log("紫叶沉疴", damage, buff, t)
            self.sim_log(str(self.yaoxing) + "紫叶沉疴", "技能施放", t)
            self.cal_num += 1
        elif self.current["time"] == 0 or self.current["name"][0] == "钩吻断肠" or self.current["name"][0] == "含锋破月" or \
                self.current["name"][0] == "紫叶沉疴" or (
                self.current["name"][0] == "商陆缀寒" and "凌然天风" in self.current_buff) or (
                self.current["name"][0] == "苍棘缚地" and self.cangji_delay[0] <= 0):
            if self.res["qixue_12"] == '3' and self.skills["紫叶沉疴"]["剩余充能"] >= 1:
                self.skills["紫叶沉疴"]["剩余充能"] -= 1
                self.skills["紫叶沉疴"]["cold_down"] = self.skills["紫叶沉疴"]["CD"]
                if "腰坠·风特效" in self.res["buff"] and self.skills["腰坠"]["剩余充能"] >= 1:
                    self.skills["腰坠"]["剩余充能"] -= 1
                    self.skills["腰坠"]["cold_down"] = self.skills["腰坠"]["CD"]
                    self.current_buff.append("风")
                    self.buffs["风"]["存在"] = True
                    self.buffs["风"]["time"] = 15
                    self.sim_log("开腰坠了！", "爆发", t)
                self.niluan_skill = '紫叶沉疴'
                if self.res["qixue_10"] == "1":  # 紫伏
                    self.buffs["紫叶"]["存在"] = True
                    self.buffs["紫叶"]["time"] = 15
                if self.res["qixue_5"] == "2":  # 沉疴
                    buff = copy.copy(self.current_buff)
                    damage = Judge(self.res, Skill(self.res).zi_li, buff).d()
                    # 沉疴温度+1
                    self.yaoxing += 1
                    if self.yaoxing < -5:
                        self.yaoxing = -5
                    elif self.yaoxing > 5:
                        self.yaoxing = 5
                    if self.yaoxing < 1:  # 触发中和
                        self.wu(t, '紫叶沉疴')
                else:
                    buff = copy.copy(self.current_buff)
                    damage = [0, ]
                self.log("紫叶沉疴", damage, buff, t)
                self.sim_log(str(self.yaoxing) + "紫叶沉疴", "技能施放", t)
                self.cal_num += 1

    # 含锋破月
    def han(self, t):
        if self.current["time"] == 0 and self.skills["含锋破月"]["剩余充能"] >= 1:
            self.skills["含锋破月"]["剩余充能"] -= 1
            self.cal_num += 1
            self.skills["含锋破月"]["cold_down"] = self.skills["含锋破月"]["CD"]
            self.current["name"] = ["含锋破月"]
            self.current["time"] = Skill(self.res).han[6]

            self.skills["飞叶满襟"]["剩余充能"] += 1

            buff = copy.copy(self.current_buff)
            damage = Judge(self.res, Skill(self.res).han, buff).d()
            self.log("含锋破月", damage, buff, t)
            self.sim_log(str(self.yaoxing) + "含锋破月", "技能施放", t)
            self.shou(t)
            self.piao(t)

            # BUFF

            # if self.niluan_skill == "川乌射罔":
            #     skill_buff_wu = copy.copy(Skill(self.res).ni)
            #     skill_buff_wu[4] = Skill(self.res).xi[4]
            #     skill_buff_wu[5] = Skill(self.res).xi[5]
            # elif self.niluan_skill == "商陆缀寒":
            #     skill_buff_wu = copy.copy(Skill(self.res).ni)
            #     skill_buff_wu[4] = Skill(self.res).shang[4]
            #     skill_buff_wu[5] = Skill(self.res).shang[5]
            # elif self.niluan_skill == "钩吻断肠":
            #     skill_buff_wu = copy.copy(Skill(self.res).ni)
            #     skill_buff_wu[4] = Skill(self.res).gou[4]
            #     skill_buff_wu[5] = Skill(self.res).gou[5]
            # else:
            #     skill_buff_wu = copy.copy(Skill(self.res).ni)
            skill_buff_wu = copy.copy(Skill(self.res).ni)
            # 爆毒
            if self.target["逆乱"]["跳数"] > 2:
                self.target["逆乱"]["跳数"] -= 2
                damage_1 = Judge(self.res, skill_buff_wu, self.niluan_buff).d()
                damage_niluan = (int(damage_1[0] * self.niluan), damage_1[1], damage_1[2])
                dam_niluan = (2 * int(damage_niluan[0]), damage_niluan[1], damage_niluan[2])
                self.log("逆乱", dam_niluan, copy.copy(self.niluan_buff), t)
            elif self.target["逆乱"]["跳数"] <= 2:
                damage_1 = Judge(self.res, skill_buff_wu, self.niluan_buff).d()
                damage_niluan = (int(damage_1[0] * self.niluan), damage_1[1], damage_1[2])
                dam_niluan = (self.target["逆乱"]["跳数"] * int(damage_niluan[0]), damage_niluan[1], damage_niluan[2])
                self.log("逆乱", dam_niluan, copy.copy(self.niluan_buff), t)
                self.target["逆乱"]["跳数"] = 0
                self.target["逆乱"]["cold_down"] = 0
                self.target["逆乱"]["存在"] = False
                self.niluan = 0
                self.niluan_buff = []

    # 飞叶满襟
    def fei(self, t):
        if self.current["time"] == 0 or self.current["name"][0] == "钩吻断肠" or self.current["name"][0] == "含锋破月" or \
                self.current["name"][0] == "紫叶沉疴" or (
                self.current["name"][0] == "商陆缀寒" and "凌然天风" in self.current_buff) or (
                self.current["name"][0] == "苍棘缚地" and self.cangji_delay[0] <= 0):
            if self.skills["飞叶满襟"]["剩余充能"] >= 1:
                self.current["name"] = ["飞叶满襟"]
                if self.current["time"] < 0.1875:
                    self.current["time"] += 0.1875
                self.skills["飞叶满襟"]["剩余充能"] -= 1
                buff = copy.copy(self.current_buff)
                damage = Judge(self.res, Skill(self.res).fei, buff).d()
                self.log("飞叶满襟", damage, buff, t)
                self.sim_log(str(self.yaoxing) + "飞叶满襟", "技能施放", t)
                self.shou(t)
                self.piao(t)
                # 爆毒
                if self.target["逆乱"]["跳数"] > 2:
                    self.target["逆乱"]["跳数"] -= 2
                    buff_list = []
                    if "凄骨" in buff:
                        buff_list.append("凄骨")
                    if "相使" in buff:
                        buff_list.append("相使")
                    if '相使' in buff:
                        buff.remove('相使')
                    if '相使' in self.niluan_buff:
                        buff.append('相使')
                    damage_niluan = Judge(self.res, Skill(self.res).ni, buff).d()
                    dam_niluan = (2 * int(damage_niluan[0] * self.niluan), damage_niluan[1], damage_niluan[2])
                    self.log("逆乱", dam_niluan, buff_list, t)
                    self.cal_num += 1
                elif self.target["逆乱"]["跳数"] <= 2:
                    buff_list = []
                    if "凄骨" in buff:
                        buff_list.append("凄骨")
                    if "相使" in buff:
                        buff_list.append("相使")
                    if '相使' in buff:
                        buff.remove('相使')
                    if '相使' in self.niluan_buff:
                        buff.append('相使')
                    damage_niluan = Judge(self.res, Skill(self.res).ni, buff).d()
                    dam_niluan = (
                        self.target["逆乱"]["跳数"] * int(damage_niluan[0] * self.niluan), damage_niluan[1],
                        damage_niluan[2])
                    self.log("逆乱", dam_niluan, buff_list, t)
                    self.target["逆乱"]["跳数"] = 0
                    self.target["逆乱"]["cold_down"] = 0
                    self.target["逆乱"]["存在"] = False
                    self.niluan = 0
                    self.niluan_buff = []
                    self.cal_num += 1

    # 银光照雪
    def yin(self, t):
        if self.current["time"] == 0 or self.current["name"][0] == "钩吻断肠" or self.current["name"][0] == "飞叶满襟" or \
                self.current["name"][0] == "紫叶沉疴" or self.current["name"][0] == "含锋破月" or (
                self.current["name"][0] == "商陆缀寒" and "凌然天风" in self.current_buff) or (
                self.current["name"][0] == "苍棘缚地" and self.cangji_delay[0] <= 0):
            if self.skills["银光照雪"]["剩余充能"] >= 1:
                # # 银光照雪取消含锋破月后摇,正式服疑似没有了
                # if self.current["name"][0] == "含锋破月":
                #     self.current["time"] -= 0.4375
                #     if self.current["time"] < 0:
                #         self.current["time"] = 0
                self.skills["银光照雪"]["剩余充能"] -= 1
                self.skills["银光照雪"]["cold_down"] = self.skills["银光照雪"]["CD"]
                buff = copy.copy(self.current_buff)
                damage = Judge(self.res, Skill(self.res).yin, buff).d()
                self.log("银光照雪", damage, buff, t)
                self.sim_log(str(self.yaoxing) + "银光照雪", "技能施放", t)
                self.cal_num += 1
                self.shou(t)
                self.piao(t)

    # 苍棘缚地
    def cang(self, t):
        if self.current["time"] == 0 and self.skills["苍棘缚地"]["剩余充能"] >= 1:
            self.current["name"] = ["苍棘缚地"]
            self.current["time"] = Skill(self.res).shang[6]
            self.cangji_delay[0] = Skill(self.res).cang[6]
            buff = copy.copy(self.current_buff)
            damage = [0, ]
            self.log("苍棘缚地施放", damage, buff, t)
            self.sim_log(str(self.yaoxing) + "苍棘缚地", "技能施放", t)
            self.cal_num += 1

    # 商陆缀寒
    def shang(self, t):
        if self.current["time"] == 0:
            if "凌然天风" in self.current_buff:
                self.skills["商陆缀寒"]["剩余充能"] -= 1
                self.skills["商陆缀寒"]["cold_down"] = self.skills["商陆缀寒"]["CD"]
                self.current["name"] = ["商陆缀寒"]
                self.current["time"] = Skill(self.res).shang[6]
                buff = copy.copy(self.current_buff)
                damage = Judge(self.res, Skill(self.res).shang, buff).d()
                self.log("商陆缀寒", damage, buff, t)
                self.sim_log(str(self.yaoxing) + "商陆缀寒", "技能施放", t)
                # 商陆缀寒温度-1
                self.yaoxing -= 1
                if self.yaoxing < -5:
                    self.yaoxing = -5
                elif self.yaoxing > 5:
                    self.yaoxing = 5
                if self.yaoxing > -1:  # 温性触发中和
                    self.wu(t, '商陆缀寒')
                # 触发奇穴6-1坚阴
                if self.res["qixue_6"] == "1" and self.niluan < 4:
                    self.niluan_buff = self.current_buff.copy()  # 逆乱快照
                    self.niluan += 1
                # 触发奇穴11-1[甘遂]
                if self.res["qixue_11"] == "1":
                    if self.skills["紫叶沉疴"]["充能"] > self.skills["紫叶沉疴"]["剩余充能"]:
                        self.skills["紫叶沉疴"]["cold_down"] -= 1
                        if self.skills["紫叶沉疴"]["cold_down"] <= 0:
                            self.skills["紫叶沉疴"]["剩余充能"] += 1
                            if self.skills["紫叶沉疴"]["充能"] > self.skills["紫叶沉疴"]["剩余充能"]:
                                self.skills["紫叶沉疴"]["cold_down"] = self.skills["紫叶沉疴"]["CD"]
                    if self.skills["苍棘缚地"]["充能"] > self.skills["苍棘缚地"]["剩余充能"]:
                        self.skills["苍棘缚地"]["cold_down"] -= 1
                        if self.skills["苍棘缚地"]["cold_down"] <= 0:
                            self.skills["苍棘缚地"]["剩余充能"] += 1
                            if self.skills["苍棘缚地"]["充能"] > self.skills["苍棘缚地"]["剩余充能"]:
                                self.skills["苍棘缚地"]["cold_down"] = self.skills["苍棘缚地"]["CD"]
                self.cal_num += 1
            else:
                # print(t, self.cal_num, self.current)
                self.niluan_skill = '商陆缀寒'
                self.skills["商陆缀寒"]["剩余充能"] -= 1
                self.skills["商陆缀寒"]["cold_down"] = self.skills["商陆缀寒"]["CD"]
                self.current["name"] = ["商陆缀寒"]
                self.current["time"] = Skill(self.res).shang[6]
                self.target["商陆缀寒"]["存在"] = True
                self.target["商陆缀寒"]["跳数"] = 1
                self.target["商陆缀寒"]["cold_down"] = Skill(self.res).shang[6]
                buff = copy.copy(self.current_buff)
                damage = [0, ]
                self.log("商陆缀寒施放", damage, buff, t)
                self.sim_log(str(self.yaoxing) + "商陆缀寒", "技能施放", t)
                # 触发奇穴6-1坚阴
                if self.res["qixue_6"] == "1" and self.niluan < 4:
                    self.niluan_buff = self.current_buff.copy()  # 逆乱快照
                    self.niluan += 1
                # 触发奇穴11-1[甘遂]
                if self.res["qixue_11"] == "1":
                    if self.skills["紫叶沉疴"]["充能"] > self.skills["紫叶沉疴"]["剩余充能"]:
                        self.skills["紫叶沉疴"]["cold_down"] -= 1
                        if self.skills["紫叶沉疴"]["cold_down"] <= 0:
                            self.skills["紫叶沉疴"]["剩余充能"] += 1
                            if self.skills["紫叶沉疴"]["充能"] > self.skills["紫叶沉疴"]["剩余充能"]:
                                self.skills["紫叶沉疴"]["cold_down"] = self.skills["紫叶沉疴"]["CD"]
                    if self.skills["苍棘缚地"]["充能"] > self.skills["苍棘缚地"]["剩余充能"]:
                        self.skills["苍棘缚地"]["cold_down"] -= 1
                        if self.skills["苍棘缚地"]["cold_down"] <= 0:
                            self.skills["苍棘缚地"]["剩余充能"] += 1
                            if self.skills["苍棘缚地"]["充能"] > self.skills["苍棘缚地"]["剩余充能"]:
                                self.skills["苍棘缚地"]["cold_down"] = self.skills["苍棘缚地"]["CD"]

                self.cal_num += 1
                # print(t, self.cal_num,self.current)

    # 钩吻断肠
    def gou(self, t):
        if self.current["time"] == 0:
            self.niluan_skill = '钩吻断肠'
            self.skills["钩吻断肠"]["剩余充能"] -= 1
            self.cal_num += 1
            self.skills["钩吻断肠"]["cold_down"] = self.skills["钩吻断肠"]["CD"]
            self.current["name"] = ["钩吻断肠"]
            self.current["time"] = Skill(self.res).gou[6]
            # 奇穴7-1[相使]
            if self.res["qixue_7"] == "1":
                self.current_buff.append("相使")
                self.buffs["相使"]["存在"] = True
                self.buffs["相使"]["time"] = 12
            buff = copy.copy(self.current_buff)
            damage = Judge(self.res, Skill(self.res).gou, buff).d()
            self.shou(t)
            self.piao(t)

            # 触发逆乱
            self.niluan_buff = self.current_buff.copy()  # 逆乱快照
            self.niluan += 1
            self.target['逆乱']['跳数'] = self.niluan_tiaoshu
            if self.niluan > 8:
                self.niluan = 8
            elif self.niluan == 1:
                self.target['逆乱']['存在'] = True
                self.target["逆乱"]["cold_down"] = Skill(self.res).ni[6]
            # 钩吻断肠温度+1
            self.yaoxing += 1
            if self.yaoxing < -5:
                self.yaoxing = -5
            elif self.yaoxing > 5:
                self.yaoxing = 5
            if self.yaoxing < 1:  # 触发中和
                self.wu(t, '钩吻断肠')
            # 沾衣大附魔额外的钩吻5温
            if self.buffs["沾衣"]["存在"] == True and self.shangku_2_gou == 1:
                self.shangku_2_gou = 0
                for i in range(0, 5):
                    self.yaoxing += 1
                    if self.yaoxing < -5:
                        self.yaoxing = -5
                    elif self.yaoxing > 5:
                        self.yaoxing = 5
                    if self.yaoxing < 1:  # 触发中和
                        self.wu(t, '沾衣未妨')
            self.log("钩吻断肠", damage, buff, t)
            self.sim_log(str(self.yaoxing) + "钩吻断肠", "技能施放", t)

    # 川乌射罔
    def xi(self, t):
        # print(t,self.skills["川乌射罔"])
        if self.current["time"] == 0 and self.skills["川乌射罔"]["剩余充能"] >= 1:
            self.niluan_skill = '钩吻断肠'
            if self.skills["川乌射罔"]["剩余充能"] == self.skills["川乌射罔"]["充能"]:
                self.skills["川乌射罔"]["cold_down"] = self.skills["川乌射罔"]["CD"]
            self.skills["川乌射罔"]["剩余充能"] -= 1
            if self.buffs["橙武"]["存在"] is True:
                self.skills["川乌射罔"]["剩余充能"] = self.skills["川乌射罔"]["充能"]

            self.current["name"] = ["川乌射罔"]
            if self.res["ping"] == 2:
                ping_k = 1
            else:
                ping_k = self.res["ping"]
            self.current["time"] = Skill(self.res).xi[6] * 4 + (ping_k - 1) * 0.0625
            self.target["川乌射罔"]["存在"] = True
            self.target["川乌射罔"]["跳数"] = 4

            self.target["川乌射罔"]["cold_down"] = Skill(self.res).xi[6]
            buff = copy.copy(self.current_buff)
            damage = [0, ]
            self.log("川乌射罔施放", damage, buff, t)
            self.sim_log(str(self.yaoxing) + "川乌射罔", "技能施放", t)
            self.cal_num += 1

    # 3跳川乌射罔
    def xi_san(self, t):
        # print(t,self.skills["川乌射罔"])
        if self.current["time"] == 0 and self.skills["川乌射罔"]["剩余充能"] >= 1:
            self.niluan_skill = '钩吻断肠'
            self.skills["川乌射罔"]["剩余充能"] -= 1
            if self.buffs["橙武"]["存在"] is True:
                self.skills["川乌射罔"]["剩余充能"] = self.skills["川乌射罔"]["充能"]
            if self.skills["川乌射罔"]["剩余充能"] == self.skills["川乌射罔"]["充能"] - 1:
                self.skills["川乌射罔"]["cold_down"] = self.skills["川乌射罔"]["CD"]
            self.current["name"] = ["川乌射罔"]
            if self.res["ping"] == 2:
                ping_k = 1
            else:
                ping_k = self.res["ping"]
            self.current["time"] = Skill(self.res).xi[6] * 3 + (ping_k - 1) * 0.0625
            self.target["川乌射罔"]["存在"] = True
            self.target["川乌射罔"]["跳数"] = 3
            self.target["川乌射罔"]["cold_down"] = Skill(self.res).xi[6]
            buff = copy.copy(self.current_buff)
            damage = [0, ]
            self.log("川乌射罔施放", damage, buff, t)
            self.sim_log(str(self.yaoxing) + "川乌射罔", "技能施放", t)
            self.cal_num += 1
            self.duan = True

    # 且待时休
    def qie(self, t):
        if self.current["time"] == 0 and self.skills["且待时休"]["剩余充能"] >= 1 and self.niluan > 3 and self.target["逆乱"][
            '跳数'] * self.target["逆乱"]['GCD'] >= 4:
            self.skills["且待时休"]["剩余充能"] -= 1
            self.skills["且待时休"]["cold_down"] = self.skills["且待时休"]["CD"]
            self.current["name"] = ["且待时休"]
            self.current["time"] = 4
            self.target["且待时休"]["存在"] = True
            self.target["且待时休"]["跳数"] = 4
            self.target["且待时休"]["cold_down"] = 1
            buff = copy.copy(self.current_buff)
            damage = Judge(self.res, Skill(self.res).qie, buff).d()
            self.log("且待时休", damage, buff, t)
            self.sim_log(str(self.yaoxing) + "且待时休", "技能施放", t)
            if self.res["qixue_6"] == "3":
                self.target["且待时休_苍"]["存在"] = True
                self.target["且待时休_苍"]["跳数"] = 4
                self.target["且待时休_苍"]["cold_down"] = 1
                buff = copy.copy(self.current_buff)
                damage = Judge(self.res, Skill(self.res).qie, buff).d()
                self.log("且待时休", damage, buff, t)
                self.sim_log(str(self.yaoxing) + "且待时休—苍", "技能施放", t)
            # 且待时休大附魔清空所有药性
            if self.res["shangku"] == "3":
                yao_k = abs(self.yaoxing)
                self.sim_log(str(self.yaoxing) + "且待时休", "大附魔中和", t)
                if yao_k > 0:
                    for i in range(0, yao_k):
                        self.wu(t, '且待时休')
                self.yaoxing = 0
            self.cal_num += 1

    # 且待时休_yitiao
    def qie_yi(self, t):
        if self.current["time"] == 0 and self.skills["且待时休"]["剩余充能"] >= 1 and self.niluan > 3 and self.target["逆乱"][
            '跳数'] * self.target["逆乱"]['GCD'] >= 4:
            self.skills["且待时休"]["剩余充能"] -= 1
            self.skills["且待时休"]["cold_down"] = self.skills["且待时休"]["CD"]
            self.current["name"] = ["且待时休"]
            self.current["time"] = Skill(self.res).gou[6]
            self.target["且待时休"]["存在"] = True
            self.target["且待时休"]["跳数"] = 1
            self.target["且待时休"]["cold_down"] = 1
            buff = copy.copy(self.current_buff)
            damage = Judge(self.res, Skill(self.res).qie, buff).d()
            self.log("且待时休", damage, buff, t)
            self.sim_log(str(self.yaoxing) + "且待时休", "技能施放", t)
            if self.res["qixue_6"] == "3":
                self.target["且待时休_苍"]["存在"] = True
                self.target["且待时休_苍"]["跳数"] = 1
                self.target["且待时休_苍"]["cold_down"] = 1
                buff = copy.copy(self.current_buff)
                damage = Judge(self.res, Skill(self.res).qie, buff).d()
                self.log("且待时休", damage, buff, t)
                self.sim_log(str(self.yaoxing) + "且待时休—苍", "技能施放", t)
            # 且待时休大附魔清空所有药性
            if self.res["shangku"] == "3":
                yao_k = abs(self.yaoxing)
                self.sim_log(str(self.yaoxing) + "且待时休", "大附魔中和", t)
                if yao_k > 0:
                    for i in range(0, yao_k):
                        self.wu(t, '且待时休')
                self.yaoxing = 0
            self.cal_num += 1
            self.duan = True

    # 沾衣未妨
    def zhan(self, t):
        if self.current["time"] == 0 or self.current["name"][0] == "钩吻断肠" or self.current["name"][0] == "飞叶满襟" or \
                self.current["name"][0] == "紫叶沉疴" or self.current["name"][0] == "含锋破月" or (
                self.current["name"][0] == "商陆缀寒" and "凌然天风" in self.current_buff) or (
                self.current["name"][0] == "苍棘缚地" and self.cangji_delay[0] <= 0):
            if self.skills["沾衣未妨"]["剩余充能"] >= 1:
                self.skills["沾衣未妨"]["剩余充能"] -= 1
                self.skills["沾衣未妨"]["cold_down"] = self.skills["沾衣未妨"]["CD"]
                self.target["沾衣未妨"]["存在"] = True
                self.target["沾衣未妨"]["跳数"] = 5
                self.target["沾衣未妨"]["cold_down"] = Skill(self.res).zhan[6] + 0.0625
                buff = copy.copy(self.current_buff)
                damage = [0, ]
                self.log("沾衣未妨", damage, buff, t)
                self.sim_log(str(self.yaoxing) + "沾衣未妨", "技能施放", t)
                self.cal_num += 1

                # 沾衣未妨伤裤附魔
                if self.res["shangku"] == "2" and self.buffs["沾衣"]["存在"] is False:
                    self.buffs["沾衣"]["存在"] = True
                    self.buffs["沾衣"]["time"] = 55
                    self.shangku_2 = True
                    self.buffs["沾附魔CD"]["存在"] = True
                    self.buffs["沾附魔CD"]["time"] = Skill(self.res).shang[6]
                    # 沾衣未妨_大附魔衍生技能

    def zhanzhan(self, t):
        if self.current["time"] == 0 or self.current["name"][0] == "钩吻断肠" or self.current["name"][0] == "飞叶满襟" or \
                self.current["name"][0] == "紫叶沉疴" or self.current["name"][0] == "含锋破月" or (
                self.current["name"][0] == "商陆缀寒" and "凌然天风" in self.current_buff) or (
                self.current["name"][0] == "苍棘缚地" and self.cangji_delay[0] <= 0):
            if self.shangku_2 is True and self.buffs["沾附魔CD"]["存在"] is False:
                self.shangku_2 = False
                self.target["沾衣未妨_附魔"]["存在"] = True
                self.target["沾衣未妨_附魔"]["跳数"] = 5
                self.target["沾衣未妨_附魔"]["cold_down"] = 0.75
                buff = copy.copy(self.current_buff)
                damage = [0, ]
                self.log("沾衣未妨", damage, buff, t)
                self.sim_log("沾衣大附魔", "技能施放", t)
                self.shangku_2_gou = 1

    # 千枝绽蕊
    def qian(self, t):
        if self.current["time"] == 0 or self.current["name"][0] == "钩吻断肠" or self.current["name"][0] == "飞叶满襟" or \
                self.current["name"][0] == "紫叶沉疴" or self.current["name"][0] == "含锋破月" or (
                self.current["name"][0] == "商陆缀寒" and "凌然天风" in self.current_buff) or (
                self.current["name"][0] == "苍棘缚地" and self.cangji_delay[0] <= 0):
            if self.skills["千枝绽蕊"]["剩余充能"] == 1:
                if self.qianzhi is False:
                    self.skills["千枝绽蕊"]["剩余充能"] -= 1
                    self.skills["千枝绽蕊"]["cold_down"] = 3
                    self.current_buff.append("千枝绽蕊")
                    self.qianzhi = True
                    self.buffs["千枝绽蕊"]["存在"] = True
                    self.buffs["千枝绽蕊"]["time"] = 999
                    buff = copy.copy(self.current_buff)
                    damage = [0, ]
                    self.log("千枝绽蕊开启", damage, buff, t)
                    self.sim_log("千枝绽蕊", "开爆发", t)
                else:
                    self.skills["千枝绽蕊"]["剩余充能"] -= 1
                    self.skills["千枝绽蕊"]["cold_down"] = 3
                    self.qianzhi = False
                    self.buffs["千枝绽蕊"]["存在"] = False
                    self.buffs["千枝绽蕊"]["time"] = 0
                    buff = copy.copy(self.current_buff)
                    damage = [0, ]
                    self.log("千枝绽蕊关闭", damage, buff, t)
                    self.sim_log("千枝绽蕊", "关爆发", t)
                self.cal_num += 1

    def shou(self, t):
        if "伤手大附魔" in self.res["buff"]:
            if self.skills["手附魔"]["剩余充能"] == 1:
                # m = random.random()
                # if self.res["models_check"] == ["稳定模式(欧皇起卦） -- 并提供当前属性收益"]:
                m = 0
                if m <= 0.10:
                    self.skills["手附魔"]["剩余充能"] -= 1
                    self.skills["手附魔"]["cold_down"] = self.skills["手附魔"]["CD"]
                    buff = copy.copy(self.current_buff)
                    damage = Judge(self.res, Skill(self.res).shou, buff).d()
                    self.log("手附魔", damage, buff, t)
                    self.sim_log("手附魔", "附魔触发", t)
                    # self.feijian_yi(t)

    # 橙武
    def cw(self, t):
        if '橙武' in self.res['buff']:
            if self.res["ping"] == 2:
                ping_k = 1
            else:
                ping_k = self.res["ping"]
            if self.current["time"] == 0:
                # print(t,self.buffs["橙武"]["存在"],self.buffs["橙武"]["time"] > Skill(self.res).xi[6] * 4 + (ping_k - 1) * 0.0625)
                if (self.buffs["橙武"]["存在"] and self.buffs["橙武"]["time"] > Skill(self.res).xi[6] * 4 + (
                        ping_k - 1) * 0.0625) or self.skills["橙武"]["剩余充能"] >= 1:
                    if self.skills["橙武"]["剩余充能"] == 1:
                        self.skills["橙武"]["剩余充能"] -= 1
                        self.skills["橙武"]["cold_down"] = self.skills["橙武"]["CD"]
                        self.buffs["橙武"]["time"] = 10
                        self.buffs["橙武"]["存在"] = True
                        self.sim_log("橙武触发", "", t)
                    # print(t,self.current)
                    if self.current["time"] == 0:
                        self.niluan_skill = '川乌射罔'
                        self.skills["川乌射罔"]["剩余充能"] -= 1
                        self.cal_num += 1
                        self.skills["川乌射罔"]["剩余充能"] = 2
                        self.skills["川乌射罔"]["cold_down"] = self.skills["川乌射罔"]["CD"]
                        self.current["name"] = ["川乌射罔"]
                        self.current["time"] = Skill(self.res).xi[6] * 4 + (ping_k - 1) * 0.0625
                        self.target["川乌射罔"]["存在"] = True
                        self.target["川乌射罔"]["跳数"] = 4
                        self.target["川乌射罔"]["cold_down"] = Skill(self.res).xi[6]
                        buff = copy.copy(self.current_buff)
                        damage = [0, ]
                        self.log("川乌射罔施放", damage, buff, t)
                        self.sim_log("川乌射罔", "技能施放", t)

    # 橙武
    def cw_san(self, t):
        if '橙武' in self.res['buff']:
            if self.res["ping"] == 2:
                ping_k = 1
            else:
                ping_k = self.res["ping"]
            if self.current["time"] == 0:
                # print(t,self.buffs["橙武"]["存在"],self.buffs["橙武"]["time"] > Skill(self.res).xi[6] * 4 + (ping_k - 1) * 0.0625)
                if (self.buffs["橙武"]["存在"] and self.buffs["橙武"]["time"] > Skill(self.res).xi[6] * 3 + (
                        ping_k - 1) * 0.0625) or self.skills["橙武"]["剩余充能"] >= 1:
                    if self.skills["橙武"]["剩余充能"] == 1:
                        self.skills["橙武"]["剩余充能"] -= 1
                        self.skills["橙武"]["cold_down"] = self.skills["橙武"]["CD"]
                        self.buffs["橙武"]["time"] = 10
                        self.buffs["橙武"]["存在"] = True
                        self.sim_log("橙武触发", "", t)
                    # print(t,self.current)
                    if self.current["time"] == 0:
                        self.niluan_skill = '川乌射罔'
                        self.skills["川乌射罔"]["剩余充能"] -= 1
                        self.cal_num += 1
                        self.skills["川乌射罔"]["剩余充能"] = 2
                        self.skills["川乌射罔"]["cold_down"] = self.skills["川乌射罔"]["CD"]
                        self.current["name"] = ["川乌射罔"]
                        self.current["time"] = Skill(self.res).xi[6] * 3 + (ping_k - 1) * 0.0625
                        self.target["川乌射罔"]["存在"] = True
                        self.target["川乌射罔"]["跳数"] = 3
                        self.target["川乌射罔"]["cold_down"] = Skill(self.res).xi[6]
                        buff = copy.copy(self.current_buff)
                        damage = [0, ]
                        self.log("川乌射罔施放", damage, buff, t)
                        self.sim_log("川乌射罔", "技能施放", t)
                        self.duan = True

    # 飘黄释放
    def piao_kai(self, t):
        if "飘黄" in self.res["buff"] and self.buffs["落黄"]["存在"] == False:
            if self.skills["飘黄"]["剩余充能"] == self.skills["飘黄"]["充能"]:
                self.skills["飘黄"]["cold_down"] = self.skills["飘黄"]["CD"]
            self.skills["飘黄"]["剩余充能"] -= 1
            self.buffs["飘黄"]["存在"] = True
            self.buffs["飘黄"]["time"] = 10
            self.buffs["落黄"]["存在"] = True
            self.buffs["落黄"]["time"] = 70
            buff = copy.copy(self.current_buff)
            damage = [0, ]
            self.log("逐云寒蕊施放", damage, buff, t)
            self.sim_log("逐云寒蕊施放", "技能施放", t)

    # 飘黄一击伤害
    def piao(self, t):
        if "飘黄" in self.res["buff"] and self.buffs["飘黄"]["存在"] is True and self.buffs["飘黄内置CD"]["存在"] is False:
            self.buffs["飘黄内置CD"]["存在"] = True
            self.buffs["飘黄内置CD"]["time"] = 1.5
            buff = copy.copy(self.current_buff)
            damage = Judge(self.res, Skill(self.res).piao, buff).d()
            self.log("飘黄", damage, buff, t)
            self.sim_log("飘黄", "触发", t)

    # 技能序列
    def xulie(self, t):
        if self.jinengxulie != [] and self.jinengxulie != ['结束']:
            for i in range(0, len(self.jinengxulie)):
                if self.cal_num == i:
                    if self.jinengxulie[i] == "银光照雪":
                        self.yin(t)
                    elif self.jinengxulie[i] == "含锋破月":
                        self.han(t)
                    elif self.jinengxulie[i] == "飞叶满襟":
                        self.fei(t)
                    elif self.jinengxulie[i] == "苍棘缚地":
                        self.cang(t)
                    elif self.jinengxulie[i] == "紫叶沉疴":
                        self.zi(t)
                    elif self.jinengxulie[i] == "沾衣未妨":
                        self.zhan(t)
                    elif self.jinengxulie[i] == "商陆缀寒":
                        self.shang(t)
                    elif self.jinengxulie[i] == "川乌射罔":
                        self.xi(t)
                    elif self.jinengxulie[i] == "奚毒射罔":
                        self.xi(t)
                    elif self.jinengxulie[i] == "钩吻断肠":
                        self.gou(t)
                    elif self.jinengxulie[i] == "且待时休":
                        self.qie(t)
                    elif self.jinengxulie[i] == "千枝绽蕊":
                        self.qian(t)
                    elif self.jinengxulie[i] == "橙武":
                        # print(t, self.cal_num, i, self.jinengxulie_xunhuan[m])
                        if "橙武" in self.res["buff"]:
                            self.cw(t)
                            if self.buffs['橙武']['存在'] and self.target["川乌射罔"]["跳数"] == 4:
                                self.cal_num += 1
                        else:
                            self.cal_num += 1
                    elif self.jinengxulie[i] == "橙武_三跳":
                        # print(t, self.cal_num, i, self.jinengxulie_xunhuan[m])
                        if "橙武" in self.res["buff"]:
                            self.cw_san(t)
                            if self.buffs['橙武']['存在'] and self.target["川乌射罔"]["跳数"] == 3:
                                self.cal_num += 1
                        else:
                            self.cal_num += 1
                    elif self.jinengxulie[i] == "川乌射罔_三跳":
                        self.xi_san(t)
                    elif self.jinengxulie[i] == "且待时休_一跳":
                        self.qie_yi(t)
                    elif self.jinengxulie[i] == "沾衣未妨(大附魔)":
                        self.zhanzhan(t)
                        if self.shangku_2 is False:
                            self.cal_num += 1
                    elif self.jinengxulie[i] == "结束":
                        self.jinengxulie = []
                        self.cal_num = 0
        else:
            for m in range(0, len(self.jinengxulie_xunhuan)):
                if self.cal_num == m:
                    # print(self.breakcishu,int(self.res["zengyifugai"]["cishu"]))
                    if self.breakcishu == int(self.res["zengyifugai"]["cishu"]) and m == 1 and self.breaktime == 999:
                        self.breaktime = t
                        # print(t,self.breaktime)

                    if self.jinengxulie_xunhuan[m] == "银光照雪":
                        self.yin(t)
                    elif self.jinengxulie_xunhuan[m] == "橙武":
                        if "橙武" in self.res["buff"]:
                            self.cw(t)
                            # if self.buffs['橙武']['存在'] and self.target["川乌射罔"]["跳数"] == 4:
                            # print(t, self.current, self.jinengxulie_xunhuan[m])
                        else:
                            self.cal_num += 1
                    elif self.jinengxulie_xunhuan[m] == "橙武_三跳":
                        # print(t, self.cal_num, i, self.jinengxulie_xunhuan[m])
                        if "橙武" in self.res["buff"]:
                            self.cw_san(t)
                            if self.buffs['橙武']['存在'] and self.target["川乌射罔"]["跳数"] == 3:
                                self.cal_num += 1
                        else:
                            self.cal_num += 1
                    elif self.jinengxulie_xunhuan[m] == "川乌射罔_三跳":
                        self.xi_san(t)
                    elif self.jinengxulie_xunhuan[m] == "且待时休_一跳":
                        self.qie_yi(t)
                    elif self.jinengxulie_xunhuan[m] == "含锋破月":
                        self.han(t)
                    elif self.jinengxulie_xunhuan[m] == "飞叶满襟":
                        self.fei(t)
                    elif self.jinengxulie_xunhuan[m] == "苍棘缚地":
                        self.cang(t)
                    elif self.jinengxulie_xunhuan[m] == "紫叶沉疴":
                        self.zi(t)
                    elif self.jinengxulie_xunhuan[m] == "沾衣未妨":
                        self.zhan(t)
                    elif self.jinengxulie_xunhuan[m] == "商陆缀寒":
                        # if m == 7:
                        #     print(t, m,self.jinengxulie_xunhuan[m],self.current,self.skills['商陆缀寒'])
                        self.shang(t)
                    elif self.jinengxulie_xunhuan[m] == "川乌射罔":
                        self.xi(t)
                    elif self.jinengxulie_xunhuan[m] == "奚毒射罔":
                        self.xi(t)
                    elif self.jinengxulie_xunhuan[m] == "钩吻断肠":
                        self.gou(t)
                    elif self.jinengxulie_xunhuan[m] == "且待时休":
                        self.qie(t)
                    elif self.jinengxulie_xunhuan[m] == "千枝绽蕊":
                        self.qian(t)
                    elif self.jinengxulie_xunhuan[m] == "结束":
                        self.cal_num = 0
                        if self.res["zengyifugai"]["fenzhong"] is True:
                            # print(self.breakcishu)
                            self.breakcishu += 1
                            # if self.breakcishu == int(self.res["zengyifugai"]["cishu"]):
                            #     self.breaktime = t
                            # print(self.breaktime)
                    elif self.jinengxulie_xunhuan[m] == "沾衣未妨(大附魔)":
                        self.zhanzhan(t)
                        if self.shangku_2 is False:
                            self.cal_num += 1
        self.time_pass(t)

    # 开始模拟
    def start(self):
        # 录入正式循环
        if self.res["zengyifugai"]["fenzhong"] is True:
            self.total_time = 9999
        elif self.res["zengyifugai"]["fenzhong"] is False:
            self.total_time = self.res["zengyifugai"]["shichang"]
        #
        # self.jinengxulie_xunhuan = ['银光照雪','苍棘缚地', '沾衣未妨', '紫叶沉疴','千枝绽蕊', '钩吻断肠', '橙武', '橙武', '橙武','银光照雪', '橙武', '商陆缀寒', '钩吻断肠', '川乌射罔', '千枝绽蕊','商陆缀寒', '商陆缀寒', '含锋破月','银光照雪', '飞叶满襟', '苍棘缚地', '沾衣未妨', '紫叶沉疴','千枝绽蕊', '钩吻断肠', '川乌射罔', '商陆缀寒', '商陆缀寒', '银光照雪','商陆缀寒', '商陆缀寒', '钩吻断肠', '橙武', '橙武', '橙武', '银光照雪','川乌射罔','千枝绽蕊', '含锋破月', '飞叶满襟', '苍棘缚地', '沾衣未妨', '紫叶沉疴','千枝绽蕊', '钩吻断肠', '川乌射罔', '银光照雪','千枝绽蕊','商陆缀寒', '商陆缀寒', '商陆缀寒', '商陆缀寒', '千枝绽蕊','钩吻断肠', '川乌射罔', '商陆缀寒', '商陆缀寒', '含锋破月', '飞叶满襟','千枝绽蕊']
        # print(self.jinengxulie_xunhuan)
        # print(self.res)
        if '结束' in self.jinengxulie_xunhuan:
            self.jinengxulie_xunhuan.remove('结束')
        if '结束' in self.jinengxulie:
            self.jinengxulie.remove('结束')
        self.jinengxulie.append('结束')
        self.jinengxulie_xunhuan.append('结束')
        for t in numpy.arange(0, self.total_time, 0.0625):
            # print(t,self.target["逆乱"])
            try:
                if self.breaktime != 999:
                    break
                self.time_start(t)
                # 这边可以放团辅技能
                self.piao_kai(t)
                # print(self.buffs["凄骨"])

                self.xulie(t)

            except Exception as e:
                # print(self.skill_sim_log)
                print(e)

        # print(self.skill_log)
        # #两件套覆盖率测试
        # asd = copy.copy(self.skill_log)
        # bufftime = 0
        # time_sta = []
        # lsst = []
        # for i in asd:
        #     if i["damage"] != 0:
        #         if i["name"] !="灵器":
        #             if i["name"] != "杀星在尾":
        #                 lsst.append(i)
        #
        # for k in lsst:
        #     m = random.random()
        #     if m <0.09:
        #         time_sta.append(k["time_stamp"])
        # # print(time_sta)
        # sta = 0
        # cc = 0
        # for i in time_sta:
        #     if sta>0 and i-sta > 6:
        #         cc+=6
        #         sta = i
        #     elif sta>0 and i-sta<6:
        #         cc += i-sta
        #         sta = i
        #     elif sta == 0:
        #         sta = i
        #
        #
        # print(cc/300000)

        # 添加破招伤害
        po_dou = 0
        po_stamp = 0.0
        po_list = []
        for i in self.skill_log:
            if i["damage"] != "0":
                if i["time_stamp"] - po_stamp >= Skill(self.res).po[6] * 5:
                    po_dou += 5
                    po_stamp = i["time_stamp"]
                    if po_dou == 5:
                        po_dou = 0
                        buff = copy.copy(i["buff"])
                        buff_list = []
                        if "凄骨" in buff:
                            buff_list.append("凄骨")
                        damage = Judge(self.res, Skill(self.res).po, buff_list).d()
                        po_list.append(
                            {
                                "name": "破",
                                "damage": int(damage[0]),
                                "buff": buff_list,
                                "time_stamp": i["time_stamp"],
                            }
                        )
        for i in po_list:
            self.skill_log.append(i)

        dam = 0
        dam_dic = {
            "商陆缀寒": 0,
            "沾衣未妨": 0,
            "川乌射罔": 0,
            "破": 0,
            "钩吻断肠": 0,
            "无方中和": 0,
            "且待时休": 0,
            "逆乱": 0,
            "苍棘缚地": 0,
            "银光照雪": 0,
            "乱暮浊茵阵": 0,
            "紫叶沉疴": 0,
            "含锋破月": 0,
            "飞叶满襟": 0,
            "紫伏": 0,
            "手附魔": 0,
            "疾根": 0,
            "飘黄": 0,
            "剑风": 0,
        }
        dam_num = {
            "商陆缀寒": 0,
            "沾衣未妨": 0,
            "川乌射罔": 0,
            "破": 0,
            "钩吻断肠": 0,
            "无方中和": 0,
            "且待时休": 0,
            "逆乱": 0,
            "苍棘缚地": 0,
            "银光照雪": 0,
            "乱暮浊茵阵": 0,
            "紫叶沉疴": 0,
            "含锋破月": 0,
            "飞叶满襟": 0,
            "紫伏": 0,
            "手附魔": 0,
            "疾根": 0,
            "飘黄": 0,
            "剑风": 0,
        }

        for i in self.skill_log:
            # if i["time_stamp"] <= self.breaktime:
            if i["name"] in dam_dic:
                dam += i["damage"]
                dam_dic[i["name"]] += i["damage"]
                if i["damage"] != 0:
                    dam_num[i["name"]] += 1
        # print(dam_dic)
        if dam == 0:
            dam = 1
        if self.res["zengyifugai"]["fenzhong"] is True:
            self.total_time = self.breaktime
        dps = int(dam / self.total_time)
        damage_shang = str(round(100 * dam_dic["商陆缀寒"] / dam, 2)) + "%"
        damage_zhan = str(round(100 * dam_dic["沾衣未妨"] / dam, 2)) + "%"
        damage_xi = str(round(100 * dam_dic["川乌射罔"] / dam, 2)) + "%"
        damage_po = str(round(100 * dam_dic["破"] / dam, 2)) + "%"
        damage_gou = str(round(100 * dam_dic["钩吻断肠"] / dam, 2)) + "%"
        damage_wu = str(round(100 * dam_dic["无方中和"] / dam, 2)) + "%"
        damage_qie = str(round(100 * dam_dic["且待时休"] / dam, 2)) + "%"
        damage_ni = str(round(100 * dam_dic["逆乱"] / dam, 2)) + "%"
        damage_cang = str(round(100 * dam_dic["苍棘缚地"] / dam, 2)) + "%"
        damage_yin = str(round(100 * dam_dic["银光照雪"] / dam, 2)) + "%"
        damage_zhen = str(round(100 * dam_dic["乱暮浊茵阵"] / dam, 2)) + "%"
        damage_zi_li = str(round(100 * dam_dic["紫叶沉疴"] / dam, 2)) + "%"
        damage_han = str(round(100 * dam_dic["含锋破月"] / dam, 2)) + "%"
        damage_fei = str(round(100 * dam_dic["飞叶满襟"] / dam, 2)) + "%"
        damage_zi = str(round(100 * dam_dic["紫伏"] / dam, 2)) + "%"
        damage_shoufumo = str(round(100 * dam_dic["手附魔"] / dam, 2)) + "%"
        damage_ji = str(round(100 * dam_dic["疾根"] / dam, 2)) + "%"
        damage_piao = str(round(100 * dam_dic["飘黄"] / dam, 2)) + "%"
        msg = {
            "data": {"dps": dps,
                     "商陆缀寒": [damage_shang, dam_num["商陆缀寒"]],
                     "沾衣未妨": [damage_zhan, dam_num["沾衣未妨"]],
                     "川乌射罔": [damage_xi, dam_num["川乌射罔"]],
                     "破": [damage_po, dam_num["破"]],
                     "钩吻断肠": [damage_gou, dam_num["钩吻断肠"]],
                     "无方中和": [damage_wu, dam_num["无方中和"]],
                     "且待时休": [damage_qie, dam_num["且待时休"]],
                     "逆乱": [damage_ni, dam_num["逆乱"]],
                     "苍棘缚地": [damage_cang, dam_num["苍棘缚地"]],
                     "银光照雪": [damage_yin, dam_num["银光照雪"]],
                     "乱暮浊茵阵": [damage_zhen, dam_num["乱暮浊茵阵"]],
                     "紫叶沉疴": [damage_zi_li, dam_num["紫叶沉疴"]],
                     "含锋破月": [damage_han, dam_num["含锋破月"]],
                     "飞叶满襟": [damage_fei, dam_num["飞叶满襟"]],
                     "紫伏": [damage_zi, dam_num["紫伏"]],
                     "剑风": ['0%', 0],
                     "手附魔": [damage_shoufumo, dam_num["手附魔"]],
                     "疾根": [damage_ji, dam_num["疾根"]],
                     "飘黄": [damage_piao, dam_num["飘黄"]],
                     "skill_log": self.skill_log,
                     "skill_sim_log": self.skill_sim_log,
                     },
            "code": 20000,
        }
        # print(msg["data"])
        return msg


from itertools import product


def cal(request):
    res = json.loads(request.body)
    # print(res)
    msg = Damage(res).start()

    k_gengu = 99
    k_gongji = 237
    k_changshu = 441
    res_gengu = copy.copy(res)

    res_gengu["gengu"] = str(int(round(int(res_gengu["gengu"]) + k_gengu, 0)))
    res_gengu["pofang"] = str(float(res_gengu["pofang"]) + 100 * k_gengu * 0.47 / 35737.5)
    res_gengu["huixin"] = str(float(res_gengu["huixin"]) + 100 * k_gengu * 0.64 / 35737.5)

    res_gongji = copy.copy(res)
    res_gongji["jichugongji"] = str(int(res_gongji["jichugongji"]) + k_gongji)
    res_wushuang = copy.copy(res)
    res_wushuang["wushuang"] = str(float(res_wushuang["wushuang"]) + k_changshu / 344.5875)
    res_pofang = copy.copy(res)
    res_pofang["pofang"] = str(float(res_pofang["pofang"]) + k_changshu / 357.375)
    res_huixin = copy.copy(res)
    res_huixin["huixin"] = str(float(res_huixin["huixin"]) + k_changshu / 357.375)
    res_huixiao = copy.copy(res)
    res_huixiao["huixiao"] = str(float(res_huixiao["huixiao"]) + k_changshu / 125.0625)
    res_pozhao = copy.copy(res)
    res_pozhao["pozhao"] = str(int(res_pozhao["pozhao"]) + k_changshu)
    dps_ori = msg["data"]["dps"]
    dps_gengu = Damage(res_gengu).start()["data"]["dps"] - dps_ori
    dps_gongji = Damage(res_gongji).start()["data"]["dps"] - dps_ori
    dps_wushuang = Damage(res_wushuang).start()["data"]["dps"] - dps_ori
    dps_pofang = Damage(res_pofang).start()["data"]["dps"] - dps_ori
    dps_huixin = Damage(res_huixin).start()["data"]["dps"] - dps_ori
    dps_huixiao = Damage(res_huixiao).start()["data"]["dps"] - dps_ori
    dps_pozhao = Damage(res_pozhao).start()["data"]["dps"] - dps_ori
    msg["data"]["dps_gengu"] = dps_gengu
    msg["data"]["dps_gongji"] = dps_gongji
    msg["data"]["dps_wushuang"] = dps_wushuang
    msg["data"]["dps_pofang"] = dps_pofang
    msg["data"]["dps_huixin"] = dps_huixin
    msg["data"]["dps_huixiao"] = dps_huixiao
    msg["data"]["dps_pozhao"] = dps_pozhao

    msg["data"]["dps_gengu_per"] = round(
        100 * dps_gengu / max([dps_gengu, dps_gongji, dps_wushuang, dps_pofang, dps_huixin, dps_huixiao, dps_pozhao]),
        2)
    msg["data"]["dps_gongji_per"] = round(
        100 * dps_gongji / max([dps_gengu, dps_gongji, dps_wushuang, dps_pofang, dps_huixin, dps_huixiao, dps_pozhao]),
        2)
    msg["data"]["dps_wushuang_per"] = round(100 * dps_wushuang / max(
        [dps_gengu, dps_gongji, dps_wushuang, dps_pofang, dps_huixin, dps_huixiao, dps_pozhao]), 2)
    msg["data"]["dps_pofang_per"] = round(
        100 * dps_pofang / max([dps_gengu, dps_gongji, dps_wushuang, dps_pofang, dps_huixin, dps_huixiao, dps_pozhao]),
        2)
    msg["data"]["dps_huixin_per"] = round(
        100 * dps_huixin / max([dps_gengu, dps_gongji, dps_wushuang, dps_pofang, dps_huixin, dps_huixiao, dps_pozhao]),
        2)
    msg["data"]["dps_huixiao_per"] = round(
        100 * dps_huixiao / max([dps_gengu, dps_gongji, dps_wushuang, dps_pofang, dps_huixin, dps_huixiao, dps_pozhao]),
        2)
    msg["data"]["dps_pozhao_per"] = round(
        100 * dps_pozhao / max([dps_gengu, dps_gongji, dps_wushuang, dps_pofang, dps_huixin, dps_huixiao, dps_pozhao]),
        2)
    # # print(msg)
    return JsonResponse(msg, safe=False)


def auth(request):
    # print(request.body)
    res = json.loads(request.body)
    result = [
        ["技能", "命中伤害", "会心伤害", "伤害预期"],
        ["商陆缀寒+奇穴秘籍", int(Judge(res, Skill(res).shang, []).t()[0]), int(Judge(res, Skill(res).shang, []).t()[1]),
         int(Judge(res, Skill(res).shang, []).d()[0])],
        ["商陆缀寒+相使+奇穴秘籍", int(Judge(res, Skill(res).shang, ["相使"]).t()[0]),
         int(Judge(res, Skill(res).shang, ["相使"]).t()[1]), int(Judge(res, Skill(res).shang, ["相使"]).d()[0])],
        ["沾衣未妨+奇穴秘籍", int(Judge(res, Skill(res).zhan, []).t()[0]), int(Judge(res, Skill(res).zhan, []).t()[1]),
         int(Judge(res, Skill(res).zhan, []).d()[0]), ],
        ["川乌射罔+奇穴秘籍", int(Judge(res, Skill(res).xi, []).t()[0]), int(Judge(res, Skill(res).xi, []).t()[1]),
         int(Judge(res, Skill(res).xi, []).d()[0])],
        ["钩吻断肠+奇穴秘籍", int(Judge(res, Skill(res).gou, []).t()[0]), int(Judge(res, Skill(res).gou, []).t()[1]),
         int(Judge(res, Skill(res).gou, []).d()[0])],
        ["无方中和+奇穴秘籍", int(Judge(res, Skill(res).wu, []).t()[0]), int(Judge(res, Skill(res).wu, []).t()[1]),
         int(Judge(res, Skill(res).wu, []).d()[0])],
        ["且待时休+奇穴秘籍", int(Judge(res, Skill(res).qie, []).t()[0]), int(Judge(res, Skill(res).qie, []).t()[1]),
         int(Judge(res, Skill(res).qie, []).d()[0])],
        ["逆乱+奇穴秘籍", int(Judge(res, Skill(res).ni, []).t()[0]), int(Judge(res, Skill(res).ni, []).t()[1]),
         int(Judge(res, Skill(res).ni, []).d()[0])],
        ["苍棘缚地+奇穴秘籍", int(Judge(res, Skill(res).cang, []).t()[0]), int(Judge(res, Skill(res).cang, []).t()[1]),
         int(Judge(res, Skill(res).cang, []).d()[0])],
        ["银光照雪+奇穴秘籍", int(Judge(res, Skill(res).yin, []).t()[0]), int(Judge(res, Skill(res).yin, []).t()[1]),
         int(Judge(res, Skill(res).yin, []).d()[0])],
        ["惊鸿掠水+奇穴秘籍", int(Judge(res, Skill(res).jing, []).t()[0]), int(Judge(res, Skill(res).jing, []).t()[1]),
         int(Judge(res, Skill(res).jing, []).d()[0])],
        ["回风微澜+奇穴秘籍", int(Judge(res, Skill(res).hui, []).t()[0]), int(Judge(res, Skill(res).hui, []).t()[1]),
         int(Judge(res, Skill(res).hui, []).d()[0])],
        ["含锋破月+奇穴秘籍", int(Judge(res, Skill(res).han, []).t()[0]), int(Judge(res, Skill(res).han, []).t()[1]),
         int(Judge(res, Skill(res).han, []).d()[0])],
        ["飞叶满襟+奇穴秘籍", int(Judge(res, Skill(res).fei, []).t()[0]), int(Judge(res, Skill(res).fei, []).t()[1]),
         int(Judge(res, Skill(res).fei, []).d()[0])],
        ["紫伏+奇穴秘籍", int(Judge(res, Skill(res).zi, []).t()[0]), int(Judge(res, Skill(res).zi, []).t()[1]),
         int(Judge(res, Skill(res).zi, []).d()[0])],
        ["疾根+奇穴秘籍", int(Judge(res, Skill(res).ji, []).t()[0]), int(Judge(res, Skill(res).ji, []).t()[1]),
         int(Judge(res, Skill(res).ji, []).d()[0])],
    ]
    msg = {
        "data": result,
        "code": 20000,
    }
    return JsonResponse(msg, safe=False)


# def cal_dan(request):
#     res = json.loads(request.body)
#     k = 1
#     result = Damage(res).start()
#     if res["huanzhuang"]["before"]["jinglian"] == "精炼0":
#         jinglian_before  = 1
#     elif res["huanzhuang"]["before"]["jinglian"] == "精炼1":
#         jinglian_before = 1.005
#     elif res["huanzhuang"]["before"]["jinglian"] == "精炼2":
#         jinglian_before = 1.0125
#     elif res["huanzhuang"]["before"]["jinglian"] == "精炼3":
#         jinglian_before = 1.02375
#     elif res["huanzhuang"]["before"]["jinglian"] == "精炼4":
#         jinglian_before = 1.038
#     elif res["huanzhuang"]["before"]["jinglian"] == "精炼5":
#         jinglian_before = 1.055
#     elif res["huanzhuang"]["before"]["jinglian"] == "精炼6":
#         jinglian_before = 1.075
#     yuanqi_before = round(int(res["huanzhuang"]["before"]["yuanqi"])*jinglian_before,0)
#     gongji_before = round(int(res["huanzhuang"]["before"]["gongji"])*jinglian_before,0)
#     huixin_before = round(int(res["huanzhuang"]["before"]["huixin"])*jinglian_before,0)
#     huixiao_before = round(int(res["huanzhuang"]["before"]["huixiao"])*jinglian_before,0)
#     pofang_before = round(int(res["huanzhuang"]["before"]["pofang"])*jinglian_before,0)
#     wushuang_before = round(int(res["huanzhuang"]["before"]["wushuang"])*jinglian_before,0)
#     pozhao_before = round(int(res["huanzhuang"]["before"]["pozhao"])*jinglian_before,0)
#     if "yuanqi" in res["huanzhuang"]["before"]["kong"]:
#         yuanqi_before += 16
#     if "gongji" in res["huanzhuang"]["before"]["kong"]:
#         gongji_before += 38
#     if "huixin" in res["huanzhuang"]["before"]["kong"]:
#         huixin_before += 72
#     if "huixiao" in res["huanzhuang"]["before"]["kong"]:
#         huixiao_before += 72
#     if "pofang" in res["huanzhuang"]["before"]["kong"]:
#         pofang_before += 72
#     if "wushuang" in res["huanzhuang"]["before"]["kong"]:
#         wushuang_before += 72
#     if "pozhao" in res["huanzhuang"]["before"]["kong"]:
#         pozhao_before += 72
#     if res["huanzhuang"]["after"]["jinglian"] == "精炼0":
#         jinglian_after  = 1
#     elif res["huanzhuang"]["after"]["jinglian"] == "精炼1":
#         jinglian_after = 1.005
#     elif res["huanzhuang"]["after"]["jinglian"] == "精炼2":
#         jinglian_after = 1.0125
#     elif res["huanzhuang"]["after"]["jinglian"] == "精炼3":
#         jinglian_after = 1.02375
#     elif res["huanzhuang"]["after"]["jinglian"] == "精炼4":
#         jinglian_after = 1.0375
#     elif res["huanzhuang"]["after"]["jinglian"] == "精炼5":
#         jinglian_after = 1.055
#     elif res["huanzhuang"]["after"]["jinglian"] == "精炼6":
#         jinglian_after = 1.075
#     yuanqi_after = round(int(res["huanzhuang"]["after"]["yuanqi"])*jinglian_after,0)
#     gongji_after = round(int(res["huanzhuang"]["after"]["gongji"])*jinglian_after,0)
#     huixin_after = round(int(res["huanzhuang"]["after"]["huixin"])*jinglian_after,0)
#     huixiao_after = round(int(res["huanzhuang"]["after"]["huixiao"])*jinglian_after,0)
#     pofang_after = round(int(res["huanzhuang"]["after"]["pofang"])*jinglian_after,0)
#     wushuang_after = round(int(res["huanzhuang"]["after"]["wushuang"])*jinglian_after,0)
#     pozhao_after = round(int(res["huanzhuang"]["after"]["pozhao"])*jinglian_after,0)
#     if "yuanqi" in res["huanzhuang"]["after"]["kong"]:
#         yuanqi_after += 16
#     if "gongji" in res["huanzhuang"]["after"]["kong"]:
#         gongji_after += 38
#     if "huixin" in res["huanzhuang"]["after"]["kong"]:
#         huixin_after += 72
#     if "huixiao" in res["huanzhuang"]["after"]["kong"]:
#         huixiao_after += 72
#     if "pofang" in res["huanzhuang"]["after"]["kong"]:
#         pofang_after += 72
#     if "wushuang" in res["huanzhuang"]["after"]["kong"]:
#         wushuang_after += 72
#     if "pozhao" in res["huanzhuang"]["after"]["kong"]:
#         pozhao_after += 72
#     new_res = copy.copy(res)
#     new_res["yuanqi"] = str(int(int(new_res["yuanqi"])+(yuanqi_after-yuanqi_before)*k))
#     new_res["jichugongji"] = str(int(int(new_res["jichugongji"])+gongji_after-gongji_before+ (yuanqi_after-yuanqi_before)*k*0.18))
#     new_res["huixin"] = str(float(new_res["huixin"])+(huixin_after-huixin_before)/357.375+(yuanqi_after-yuanqi_before)*100*k *0.47/35737.5)
#     new_res["huixiao"] = str(float(new_res["huixiao"])+(huixiao_after-huixiao_before)/125.0625)
#     new_res["pofang"] = str(float(new_res["pofang"])+(pofang_after-pofang_before)/357.375+(yuanqi_after-yuanqi_before)*100*k *0.3/35737.5)
#     new_res["wushuang"] = str(float(new_res["wushuang"])+ (wushuang_after-wushuang_before)/344.5875)
#     new_res["pozhao"] = str(float(new_res["pozhao"])   +(pozhao_after-pozhao_before))
#     new_result = Damage(new_res).start()
#     ms = {
#         'dps':result["data"]["dps"],
#         'new_dps':new_result["data"]["dps"]
#     }
#     msg = {
#                 "data": ms,
#                 "code": 20000,
#             }
#     return JsonResponse(msg, safe=False)


# 下载茗伊BUFF监控
import os

path = os.path.dirname(__file__)


def buff_download(request):
    file = open(path + '/buff.jx3dat', 'rb')
    response = HttpResponse(content_type='application/octet-stream')
    response['Content-Disposition'] = "attachment;filename= buff.jx3dat"
    response = FileResponse(file)
    return response


import pymysql
from backend.db_set import db

db_data = db


def db_login():
    try:
        db = pymysql.connect(db_data['server'], db_data['user_name'], db_data['pwd'], "jx3", charset='utf8')
    except Exception as e:
        os.system('reboot')
    return db


def check_zhuangbei(request):
    res = json.loads(request.body)
    # print(res)
    db = db_login()
    cursor = db.cursor()
    sql = "select id,name,position,level,beizhu from jx3_equipment_wufang where position = '{0}' and level>=3600 ".format(
        res['positon'])
    wushuang_sql = " and name not like '无皇%'"
    if res["wuhuang"] is False:
        sql += wushuang_sql + ' ORDER BY level desc'
    else:
        sql += ' ORDER BY level desc'
    cursor.execute(sql)
    resu = cursor.fetchall()
    # print(resu)
    cursor.close()
    db.close()
    # print(res)
    msg = {
        "data": resu,
        "code": 20000,
    }
    return JsonResponse(msg, safe=False)


def zhuangbei_detail(request):
    res = json.loads(request.body)
    # print(res)
    db = db_login()
    cursor = db.cursor()
    sql = "select * from jx3_equipment_wufang where id = '{0}'".format(res['value'])
    cursor.execute(sql)
    resu = cursor.fetchone()
    cursor.close()
    db.close()
    msg = {
        "data": resu,
        "code": 20000,
    }
    return JsonResponse(msg, safe=False)


def store_zhuangbei_fangan(request):
    res = json.loads(request.body)
    db = db_login()
    cursor = db.cursor()
    sql = 'insert into jx3_equipment_fangan(uuid,content) VALUES ("{0}","{1}")'.format(res["uuid"], res)
    # print(sql)
    cursor.execute(sql)
    db.commit()
    cursor.close()
    db.close()
    msg = {
        "code": 20000,
    }
    return JsonResponse(msg, safe=False)


def read_zhuangbei_fangan(request):
    # print(request)
    res = json.loads(request.body)
    # print(res['uuid'])
    db = db_login()
    cursor = db.cursor()
    sql = "select content from jx3_equipment_fangan where uuid = '{0}'".format(res['uuid'])
    cursor.execute(sql)
    resu = eval(cursor.fetchone()[0])
    # print(type(resu),resu)
    cursor.close()
    db.close()
    msg = {
        "data": resu,
        "code": 20000,
    }
    return JsonResponse(msg, safe=False)
